home *** CD-ROM | disk | FTP | other *** search
- /*
- File: ThreadClasses.h
-
- Copyright: © 1991-1994 by Apple Computer, Inc.
- All rights reserved.
-
- Part of the AOCE Sample SMSAM Package. Consult the license
- which came with this software for your specific legal rights.
-
- */
-
-
-
- #ifndef __THREADCLASSES__
- #define __THREADCLASSES__
-
- #ifndef __THREADS__
- #include "Threads.h"
- #endif
-
- #ifndef __FAILURE__
- #include "Failure.h"
- #endif
-
- #ifndef __TIMER__
- #include <Timer.h>
- #endif
-
- /***********************************|****************************************/
-
- typedef unsigned long (*FNUL)( unsigned long );
- typedef unsigned long (*FNULUL)( unsigned long, unsigned long );
-
- /***********************************|****************************************/
-
- class TThread
- {
- public:
- TThread ( );
- virtual ~TThread ();
-
- virtual void Sleep ( unsigned long howLongToSleep = 0 ) = 0;
- virtual void Yield ( ) = 0;
- virtual void Wake ( ) = 0;
-
- virtual OSType GetDescriptor() = 0;
-
- virtual void BeginCritical ( ) = 0;
- virtual void EndCritical ( ) = 0;
-
- virtual void * GetExceptionChain ( ) const = 0;
- virtual void SetExceptionChain ( void * ) = 0;
-
-
- // Routines to manipulate the threads.
- static TThread * GetCurrentThread ();
- static void YieldCurrentThread ( TThread* threadToYieldTo = nil );
-
- static unsigned long GetCurrentThreadStackSpace ( );
-
- static unsigned long GetThreadCount ( );
- static TThread * GetThread ( unsigned long index );
-
- #if debug
- virtual ostream& operator << ( ostream& s );
- #endif
-
- protected:
- TThread * fNext; // for the list of all threads.
- static TThread * gCurrentThread;
- static TThread * gThreadList;
- };
-
- /***********************************|****************************************/
-
- class TThreadStatusWindow;
-
- /***********************************|****************************************/
-
- class TThreadManagerThread : public TThread
- {
- public: TThreadManagerThread ( FNULUL proc, unsigned long param1, unsigned long param2, OSType descriptor );
- protected: TThreadManagerThread ( OSType descriptor );
- public: virtual ~TThreadManagerThread ();
-
- virtual void Sleep ( unsigned long howLongToSleep = 0 );
- virtual void Yield ( );
- virtual void Wake ( );
-
- virtual OSType GetDescriptor();
-
- virtual void BeginCritical ( );
- virtual void EndCritical ( );
-
- virtual void * GetExceptionChain ( ) const;
- virtual void SetExceptionChain ( void * );
-
- static void WakeUpSleepingThreadsTask ( );
-
- #if debug
- virtual ostream& operator << ( ostream& s );
- friend class TThreadStatusWindow;
- #endif
-
- protected:
- // These get called by the Thread Manager as this thread gets swapped in and out.
- static pascal void ThreadManagerSwitchInProc ( ThreadID threadBeingSwitched, void* switchProcParam );
- static pascal void ThreadManagerSwitchOutProc ( ThreadID threadBeingSwitched, void* switchProcParam );
- static pascal void TThreadManagerThreadTerminationProc ( ThreadID threadID, void * terminationProcParam );
-
- static pascal void WakeUpOutstandingParamBlockCalls ( ) ;
- static pascal void WakeUpSleepingThreadTimeManagerCallback ( );
-
- friend pascal unsigned long TThreadInstantiationWrapper( TThreadManagerThread* thread);
-
-
- FNULUL fThreadEntry;
- unsigned long fParam1;
- unsigned long fParam2;
-
- ThreadID fThreadID;
-
- OSType fDescriptor;
- void * fExceptionChainTop;
- long fA5;
-
- unsigned long fWakeThreadAfter;
- TMTask fWakeUpTimeManagerTask;
- TMTask fThreadExecutionTimeManagerTask;
-
- const void * fOutstandingParamBlock;
-
- ThreadTaskRef* fThreadTaskRef;
- };
-
- /***********************************|****************************************
- *
- * Macros to make switching from Herman's thread stuff to the new thread
- * class.
- *
- ***********************************|****************************************/
-
- #define newThreads 1
-
- #define TNormalMode 0
- #define TVMSafeMode 1
-
- void TSleep ( unsigned long x );
- void TYield();
-
- void TSetRefCon(OSType x);
- OSType TGetRefCon();
-
- TThread* createThread(OSType name,
- void* proc, unsigned long stkSize,
- unsigned long p1, unsigned long p2,
- short execMode);
-
- # define thread TThread
-
- #endif
-